/**
 * 
 */
package za.ac.wits.elen7045vikings.aps;


import javax.servlet.http.HttpServlet;

/**
 * @author Administrator
 *
 */


import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Cookie;

    /**
     * @author Mokoena F.R 
     *
     */
public class LoginServlet extends HttpServlet implements Servlet
    {


        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException
        {
            String user = request.getParameter("username");
            String password = request.getParameter("password");
            //String newUser = request.getParameter("newuser");
            
                                 
           if(user.equals("testUser")&& password.equals("testPass"))
           {
        	   getServletContext().getRequestDispatcher("/welcome.jsp").forward(request, response);
        	   
           }else
           {
               
                   // send them back to register as a new user
                   String message = "That username has already been taken.  Please select another.";
                   request.getSession().setAttribute("login_failed", message);
                   getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
               //getServletContext().getRequestDispatcher("/loginError.jsp").forward(request, response);
           }
           


                 
      }
       	

        

        protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
        {
            doPost(request,response);
        }
}
